{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)\n",
    "\n",
    "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/nlu/blob/master/examples/colab/healthcare/assertion/few_shot_assertion_classifier.ipynb)\n"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Assign assertion status to clinical entities\n",
    "\n",
    "Classes are: `absent`, `present`, `conditional`, `associated_with_someone_else`, `hypothetical`, `possible`"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Starting the session"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "from johnsnowlabs import nlp\n",
    "nlp.install()\n",
    "nlp.start()"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Loading the data"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "data = (\n",
    "            \"\"\"Includes hypertension and chronic obstructive pulmonary disease.\"\"\"\n",
    "        )"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-09-09T14:02:59.655452100Z",
     "start_time": "2024-09-09T14:02:59.634164800Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## [Assign assertion status to clinical entities](https://nlp.johnsnowlabs.com/2024/04/15/assertion_fewshotclassifier_en.html)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning::Spark Session already created, some configs may not take.\n",
      "Warning::Spark Session already created, some configs may not take.\n",
      "assertion_fewshotclassifier download started this may take some time.\n",
      "[OK!]\n",
      "sentence_detector_dl download started this may take some time.\n",
      "Approximate size to download 354.6 KB\n",
      "[OK!]\n",
      "pos_anc download started this may take some time.\n",
      "Approximate size to download 3.9 MB\n",
      "[OK!]\n",
      "Warning::Spark Session already created, some configs may not take.\n"
     ]
    }
   ],
   "source": [
    "res = nlp.load(\"en.few_assert_shot_classifier\").predict(data, output_level='chunk')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-09-09T14:22:02.470834500Z",
     "start_time": "2024-09-09T14:21:37.585408700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "  assertion assertion_confidence  \\\n0   present                  1.0   \n0   present                  1.0   \n\n                                            document   matched_pos  \\\n0  Includes hypertension and chronic obstructive ...  hypertension   \n0  Includes hypertension and chronic obstructive ...       disease   \n\n                                pos  \n0  [VBZ, NN, CC, JJ, JJ, JJ, NN, .]  \n0  [VBZ, NN, CC, JJ, JJ, JJ, NN, .]  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>assertion</th>\n      <th>assertion_confidence</th>\n      <th>document</th>\n      <th>matched_pos</th>\n      <th>pos</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>present</td>\n      <td>1.0</td>\n      <td>Includes hypertension and chronic obstructive ...</td>\n      <td>hypertension</td>\n      <td>[VBZ, NN, CC, JJ, JJ, JJ, NN, .]</td>\n    </tr>\n    <tr>\n      <th>0</th>\n      <td>present</td>\n      <td>1.0</td>\n      <td>Includes hypertension and chronic obstructive ...</td>\n      <td>disease</td>\n      <td>[VBZ, NN, CC, JJ, JJ, JJ, NN, .]</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-09-09T14:22:02.515663Z",
     "start_time": "2024-09-09T14:22:02.478142Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
